package com.gk.ScheduleTask;
import com.alibaba.fastjson.JSON;
import com.gk.bean.BillTypeCommon;
import com.gk.bean.ZxyUploadbillGuoyao;
import com.gk.dao.ZxyUploadbillGuoyaoDao;
import com.gk.http.entity.HttpResult;
import com.gk.service.InBillService;
import com.gk.service.OutBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 上传单据到国控定时器
 */
@Component
@EnableScheduling
@EnableAsync
@Slf4j
public class UploadGkBillMultithreadScheduleTask {
    @Resource
    private InBillService inBillService;
    @Resource
    private OutBillService outBillService;
    @Resource
    private ZxyUploadbillGuoyaoDao zxyUploadbillGuoyaoDao;

    @Async
    @Scheduled(fixedDelay = 100000)
    //TODO 上传采订单
    public void UploadBuy() {
        List<ZxyUploadbillGuoyao> uploadBillByBilltypes = zxyUploadbillGuoyaoDao.getUploadBillByBilltype(BillTypeCommon.buyBill);
        for (ZxyUploadbillGuoyao uploadBillByBilltype : uploadBillByBilltypes) {
            HttpResult httpResult = inBillService.CgBillUpload(uploadBillByBilltype.getBillcode());
//            log.info("上传采购定时器层返回接口"+ JSON.toJSONString(httpResult));
        }
    }

    @Async
    @Scheduled(fixedDelay = 120000)
    //TODO 上传采销售
    public void UploadSale() {
        List<ZxyUploadbillGuoyao> uploadBillByBilltypes = zxyUploadbillGuoyaoDao.getUploadBillByBilltype(BillTypeCommon.saleBill);
        for (ZxyUploadbillGuoyao uploadBillByBilltype : uploadBillByBilltypes) {
            HttpResult httpResult = outBillService.XsBillUpload(uploadBillByBilltype.getBillcode());
//            log.info("上传采销售定时器层返回接口"+ JSON.toJSONString(httpResult));
        }
    }
    @Async
    @Scheduled(fixedDelay = 140000)
    //TODO 上传采购退货
    public void UploadBuyBack() {
        List<ZxyUploadbillGuoyao> uploadBillByBilltypes = zxyUploadbillGuoyaoDao.getUploadBillByBilltype(BillTypeCommon.buyBackBill);
        for (ZxyUploadbillGuoyao uploadBillByBilltype : uploadBillByBilltypes) {
            HttpResult httpResult = outBillService.CgBackBillUpload(uploadBillByBilltype.getBillcode());
//            log.info("上传采购退货定时器层返回接口"+ JSON.toJSONString(httpResult));
        }

    }
    @Async
    @Scheduled(fixedDelay = 160000)
    //TODO 上传销售退货
    public void UploadSaleBack() {
        List<ZxyUploadbillGuoyao> uploadBillByBilltypes = zxyUploadbillGuoyaoDao.getUploadBillByBilltype(BillTypeCommon.saleBackBill);
        for (ZxyUploadbillGuoyao uploadBillByBilltype : uploadBillByBilltypes) {
            HttpResult httpResult = inBillService.XsBackBillUpload(uploadBillByBilltype.getBillcode());
//            log.info("上传销售退货定时器层返回接口"+ JSON.toJSONString(httpResult));
        }
    }

}
